#include "UserDialog.h"
#include "ui_userinfo.h"
#include <QPainter>

UserDialog::UserDialog(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UserDialog)
{
    ui->setupUi(this);
    ui->image->setWindowFlags(Qt::FramelessWindowHint);
    // 设置样式表，使得QLabel具有圆角效果
    ui->image->setStyleSheet("QLabel {border-radius: 30px;}");
    ui->label->setFixedHeight(45);
    ui->label->setStyleSheet("QLabel {"
                             "  color: blue;"
                             "  font-size: 25px;"
                             "  font-weight: bold;"
                             "  border: none;"
                             "}");
}

UserDialog::~UserDialog()
{
    delete ui;
}

void UserDialog::setUser(QString name, QImage image)
{
    image = image.scaled(ui->image->width(), ui->image->height());
    QPixmap mp = QPixmap::fromImage(image);

    ui->label->setText(name);
    ui->image->setPixmap(mp);
}

void UserDialog::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);

    QPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
}
